﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.DataReport
{
    public partial class AreaXianQuPSLList : BasePage
    {
        string source = "";

        public AreaXianQuPSLList()
        {
            this.ModuleNo = Module.药品统计分析.ToString();
            this.PageOperateType = OperateType.药品汇总统计.ToString();
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //BindArea();
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                BindData();
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_chaxun_Click(object sender, EventArgs e)
        {
            BindData();
        }
        /// <summary>
        /// 查询方法
        /// modify by张雄   2011.5.4
        /// </summary>
        public void BindData()
        {
            int t = 0;
            string areaid = HZ.Supervise.Web.Function.GetAreaIDBySQL(AreaControl1.SelectedAreaID);
            
            string orderby = this.OrderFileds.SelectedItem.Value + "  " + this.OrderType.SelectedItem.Value;//String.Empty;
            if (dropsource.SelectedValue != "全部")     //判断是否等于‘全部’  ‘是’不加条件‘否’加入采购类型的查询条件
            {
                source = this.dropsource.SelectedValue;
            }
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getAreaXianquList(areaid, orderby, source, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;
            gvwXianQuInfo.PageSize = AspNetPager1.PageSize;
            this.gvwXianQuInfo.DataSource = dt;
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            this.gvwXianQuInfo.DataBind();
        }
        /// <summary>
        /// 导出
        /// create by 张雄  2011.5.5
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;
            string areaid = HZ.Supervise.Web.Function.GetAreaIDBySQL(AreaControl1.SelectedAreaID);
            string orderby = this.OrderFileds.SelectedValue + " " + this.OrderType.SelectedValue;   //取得排序字段的值

            if (dropsource.SelectedValue != "全部")  //判断是否等于‘全部’  ‘是’不加条件‘否’加入采购类型的查询条件
            {
                source = this.dropsource.SelectedValue;
            }
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getAreaXianquList(areaid, orderby,source, 0, 0, out t);
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            ExportFile.Instance.ExportData(dt, gvwXianQuInfo, this.Page);
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
    }
}
